package com.common.baseModel;

import com.common.constant.ResCodeEnum;
import com.common.constant.BaseConst;
import lombok.Data;

import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @ClassName ResponseResult
 * @Description TODO
 * @Author 吃麻椒的花酱
 * @Date 2022/2/9 20:38
 * @Version 1.0
 */
@Data
public class JsonResult<T> implements Serializable {
    private int code;
    private String msg;
    private T data;

    public static <T> JsonResult<T> createSuccess(String msg) {
        JsonResult<T> result = new JsonResult<>();
        result.code = BaseConst.ResCode.SUCCESS;
        result.msg = msg;
        return result;
    }

    public static <T> JsonResult<T> create(ResCodeEnum resCodeDescribe, String msg) {
        JsonResult<T> result = new JsonResult<>();
        result.code = resCodeDescribe.getCode();
        result.msg = msg;
        return result;
    }

    public static <T> JsonResult<T> create(ResCodeEnum resCodeDescribe) {
        JsonResult<T> result = new JsonResult<>();
        result.code = resCodeDescribe.getCode();
        result.msg = resCodeDescribe.getDescribe();
        return result;
    }

    public static <T> JsonResult<T> createError(String msg) {
        JsonResult<T> result = new JsonResult<>();
        result.code = ResCodeEnum.ERROR.getCode();
        result.msg = msg;
        return result;
    }

    public static <T> JsonResult<T> create(String msg, T data) {
        JsonResult<T> result = new JsonResult<>();
        result.code = ResCodeEnum.SUCCESS.getCode();
        result.msg = msg;
        result.data = data;
        return result;
    }

    public static <T> JsonResult<T> create(int code, String msg, T data) {
        JsonResult<T> result = new JsonResult<>();
        result.code = code;
        result.msg = msg;
        result.data = data;
        return result;
    }

    public static <T> JsonResult<T> create(int code, T data) {
        JsonResult<T> result = new JsonResult<>();
        result.code = code;
        result.msg = ResCodeEnum.SUCCESS.getDescribe();
        result.data = data;
        return result;
    }

    public static <T> JsonResult<T> create(T data) {
        JsonResult<T> result = new JsonResult<>();
        result.code = ResCodeEnum.SUCCESS.getCode();
        result.msg = ResCodeEnum.SUCCESS.getDescribe();
        result.data = data;
        return result;
    }

    public static Map<String, Object> create(int code, String msg, int count, Object data) {
        Map<String, Object> result = new LinkedHashMap<>();
        result.put("code", code);
        result.put("msg", msg);
        result.put("count", count);
        result.put("data", data);
        return result;
    }


    public static <T> JsonResult<T> isOk() {
        JsonResult<T> result = new JsonResult<>();
        result.code = ResCodeEnum.SUCCESS.getCode();
        result.msg = ResCodeEnum.SUCCESS.getDescribe();
        return result;
    }

}
